"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const vue_1 = require("vue");
const fileApi_1 = require("@/api/fileApi");
const element_plus_1 = require("element-plus");
const emit = defineEmits(['upload-success', 'close-dialog']);
// 重置表单状态
const reset = () => {
    selectedFile.value = null;
    previewData.value = null;
    selectedTypeId.value = null;
    chunkType.value = 1;
};
const __VLS_exposed = {
    reset,
};
defineExpose(__VLS_exposed);
// 文件类型列表
const fileTypes = (0, vue_1.ref)([]);
// 选中的文件对象
const selectedFile = (0, vue_1.ref)(null);
// 预上传返回的预览数据
const previewData = (0, vue_1.ref)(null);
// 选中的文件类型ID
const selectedTypeId = (0, vue_1.ref)(null);
// 切分类型 (0:不切分,1:固定长度切分,2:标题增强切分)
const chunkType = (0, vue_1.ref)(1);
// 获取文件类型列表
const loadFileTypes = () => __awaiter(void 0, void 0, void 0, function* () {
    var _a, _b;
    try {
        const response = yield (0, fileApi_1.getFileTypes)();
        if ((_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.typeSummaries) {
            fileTypes.value = response.data.data.typeSummaries.map((item) => ({
                id: item.typeId,
                name: item.name,
            }));
        }
        else {
            throw new Error('接口返回数据格式不正确');
        }
    }
    catch (error) {
        console.error('获取文件类型失败:', error);
        element_plus_1.ElMessage.error('文件类型加载失败，请点击重试按钮');
    }
});
// 组件初始化时加载文件类型
(0, vue_1.onMounted)(() => {
    loadFileTypes();
});
// 处理文件选择事件
const handleFileSelect = (event) => __awaiter(void 0, void 0, void 0, function* () {
    if (event.target.files && event.target.files.length > 0) {
        selectedFile.value = event.target.files[0];
        yield processFileUpload();
    }
});
const handleFileDrop = (event) => __awaiter(void 0, void 0, void 0, function* () {
    event.preventDefault();
    if (event.dataTransfer.files && event.dataTransfer.files.length > 0) {
        // 检查是否已有选中文件
        if (selectedFile.value) {
            element_plus_1.ElMessage.warning('已有文件正在处理，请等待完成');
            return;
        }
        selectedFile.value = event.dataTransfer.files[0];
        yield processFileUpload();
    }
    else {
        element_plus_1.ElMessage.warning('请拖放有效的文件');
    }
});
const processFileUpload = () => __awaiter(void 0, void 0, void 0, function* () {
    const formData = new FormData();
    formData.append('file', selectedFile.value);
    formData.append('type', selectedTypeId.value);
    formData.append('chunkType', chunkType.value);
    try {
        // 调用预上传接口
        const response = yield (0, fileApi_1.preUpload)(formData);
        previewData.value = response.data.data;
        emit('upload-success', {
            chunks: response.data.data.chunks,
            filename: response.data.data.filename,
            typeId: selectedTypeId.value,
            chunkType: chunkType.value,
        });
    }
    catch (error) {
        console.error('预上传处理失败:', error);
        element_plus_1.ElMessage.error('文件预处理失败：' + error.message);
    }
});
// 确认提交处理
const handleConfirm = () => __awaiter(void 0, void 0, void 0, function* () {
    if (!previewData.value) {
        element_plus_1.ElMessage.warning('请先完成预上传');
        return;
    }
    try {
        yield (0, fileApi_1.confirmUpload)(Object.assign(Object.assign({}, previewData.value), { file: selectedFile.value }));
        element_plus_1.ElMessage.success('文件上传成功!');
        // 重置状态
        previewData.value = null;
        selectedFile.value = null;
    }
    catch (error) {
        console.error('提交失败:', error);
        element_plus_1.ElMessage.error('文件提交失败：' + error.message);
    }
});
debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
const __VLS_ctx = {};
let __VLS_components;
let __VLS_directives;
/** @type {__VLS_StyleScopedClasses['file-drop-zone']} */ ;
/** @type {__VLS_StyleScopedClasses['form-group']} */ ;
// CSS variable injection 
// CSS variable injection end 
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(Object.assign({ class: "upload-container" }, { ref: "uploadContainer" }));
/** @type {typeof __VLS_ctx.uploadContainer} */ ;
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(Object.assign({ class: "form-group" }));
__VLS_asFunctionalElement(__VLS_intrinsicElements.label, __VLS_intrinsicElements.label)({});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(Object.assign({ class: "type-select-container" }));
const __VLS_0 = {}.ElSelect;
/** @type {[typeof __VLS_components.ElSelect, typeof __VLS_components.elSelect, typeof __VLS_components.ElSelect, typeof __VLS_components.elSelect, ]} */ ;
// @ts-ignore
const __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0(Object.assign({ 'onChange': {} }, { modelValue: (__VLS_ctx.selectedTypeId), placeholder: "请选择文件类型" })));
const __VLS_2 = __VLS_1(Object.assign({ 'onChange': {} }, { modelValue: (__VLS_ctx.selectedTypeId), placeholder: "请选择文件类型" }), ...__VLS_functionalComponentArgsRest(__VLS_1));
let __VLS_4;
let __VLS_5;
let __VLS_6;
const __VLS_7 = {
    onChange: (__VLS_ctx.loadFileTypes)
};
__VLS_3.slots.default;
for (const [type] of __VLS_getVForSourceType((__VLS_ctx.fileTypes))) {
    const __VLS_8 = {}.ElOption;
    /** @type {[typeof __VLS_components.ElOption, typeof __VLS_components.elOption, ]} */ ;
    // @ts-ignore
    const __VLS_9 = __VLS_asFunctionalComponent(__VLS_8, new __VLS_8({
        key: (type.id),
        label: (type.name),
        value: (type.id),
    }));
    const __VLS_10 = __VLS_9({
        key: (type.id),
        label: (type.name),
        value: (type.id),
    }, ...__VLS_functionalComponentArgsRest(__VLS_9));
}
var __VLS_3;
if (!__VLS_ctx.fileTypes.length) {
    const __VLS_12 = {}.ElButton;
    /** @type {[typeof __VLS_components.ElButton, typeof __VLS_components.elButton, typeof __VLS_components.ElButton, typeof __VLS_components.elButton, ]} */ ;
    // @ts-ignore
    const __VLS_13 = __VLS_asFunctionalComponent(__VLS_12, new __VLS_12(Object.assign(Object.assign({ 'onClick': {} }, { type: "primary" }), { class: "retry-btn" })));
    const __VLS_14 = __VLS_13(Object.assign(Object.assign({ 'onClick': {} }, { type: "primary" }), { class: "retry-btn" }), ...__VLS_functionalComponentArgsRest(__VLS_13));
    let __VLS_16;
    let __VLS_17;
    let __VLS_18;
    const __VLS_19 = {
        onClick: (__VLS_ctx.loadFileTypes)
    };
    __VLS_15.slots.default;
    var __VLS_15;
}
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(Object.assign({ class: "form-group" }));
__VLS_asFunctionalElement(__VLS_intrinsicElements.label, __VLS_intrinsicElements.label)({});
const __VLS_20 = {}.ElRadioGroup;
/** @type {[typeof __VLS_components.ElRadioGroup, typeof __VLS_components.elRadioGroup, typeof __VLS_components.ElRadioGroup, typeof __VLS_components.elRadioGroup, ]} */ ;
// @ts-ignore
const __VLS_21 = __VLS_asFunctionalComponent(__VLS_20, new __VLS_20(Object.assign({ 'onChange': {} }, { modelValue: (__VLS_ctx.chunkType) })));
const __VLS_22 = __VLS_21(Object.assign({ 'onChange': {} }, { modelValue: (__VLS_ctx.chunkType) }), ...__VLS_functionalComponentArgsRest(__VLS_21));
let __VLS_24;
let __VLS_25;
let __VLS_26;
const __VLS_27 = {
    onChange: (__VLS_ctx.processFileUpload)
};
__VLS_23.slots.default;
const __VLS_28 = {}.ElRadio;
/** @type {[typeof __VLS_components.ElRadio, typeof __VLS_components.elRadio, typeof __VLS_components.ElRadio, typeof __VLS_components.elRadio, ]} */ ;
// @ts-ignore
const __VLS_29 = __VLS_asFunctionalComponent(__VLS_28, new __VLS_28({
    label: (0),
}));
const __VLS_30 = __VLS_29({
    label: (0),
}, ...__VLS_functionalComponentArgsRest(__VLS_29));
__VLS_31.slots.default;
var __VLS_31;
const __VLS_32 = {}.ElRadio;
/** @type {[typeof __VLS_components.ElRadio, typeof __VLS_components.elRadio, typeof __VLS_components.ElRadio, typeof __VLS_components.elRadio, ]} */ ;
// @ts-ignore
const __VLS_33 = __VLS_asFunctionalComponent(__VLS_32, new __VLS_32({
    label: (1),
}));
const __VLS_34 = __VLS_33({
    label: (1),
}, ...__VLS_functionalComponentArgsRest(__VLS_33));
__VLS_35.slots.default;
var __VLS_35;
const __VLS_36 = {}.ElRadio;
/** @type {[typeof __VLS_components.ElRadio, typeof __VLS_components.elRadio, typeof __VLS_components.ElRadio, typeof __VLS_components.elRadio, ]} */ ;
// @ts-ignore
const __VLS_37 = __VLS_asFunctionalComponent(__VLS_36, new __VLS_36({
    label: (2),
}));
const __VLS_38 = __VLS_37({
    label: (2),
}, ...__VLS_functionalComponentArgsRest(__VLS_37));
__VLS_39.slots.default;
var __VLS_39;
const __VLS_40 = {}.ElRadio;
/** @type {[typeof __VLS_components.ElRadio, typeof __VLS_components.elRadio, typeof __VLS_components.ElRadio, typeof __VLS_components.elRadio, ]} */ ;
// @ts-ignore
const __VLS_41 = __VLS_asFunctionalComponent(__VLS_40, new __VLS_40({
    label: (3),
}));
const __VLS_42 = __VLS_41({
    label: (3),
}, ...__VLS_functionalComponentArgsRest(__VLS_41));
__VLS_43.slots.default;
var __VLS_43;
var __VLS_23;
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(Object.assign(Object.assign(Object.assign({ onDragover: () => { } }, { onDrop: (__VLS_ctx.handleFileDrop) }), { onClick: (...[$event]) => {
        __VLS_ctx.$refs.fileInput.click();
    } }), { class: "file-drop-zone" }));
__VLS_asFunctionalElement(__VLS_intrinsicElements.input)(Object.assign({ onChange: (__VLS_ctx.handleFileSelect) }, { ref: "fileInput", type: "file", accept: ".docx,.xlsx,.doc,.pdf" }));
/** @type {typeof __VLS_ctx.fileInput} */ ;
__VLS_asFunctionalElement(__VLS_intrinsicElements.p, __VLS_intrinsicElements.p)({});
if (__VLS_ctx.previewData) {
    const __VLS_44 = {}.ChunkPreview;
    /** @type {[typeof __VLS_components.ChunkPreview, ]} */ ;
    // @ts-ignore
    const __VLS_45 = __VLS_asFunctionalComponent(__VLS_44, new __VLS_44(Object.assign({ 'onConfirm': {} }, { chunks: (__VLS_ctx.previewData.chunks) })));
    const __VLS_46 = __VLS_45(Object.assign({ 'onConfirm': {} }, { chunks: (__VLS_ctx.previewData.chunks) }), ...__VLS_functionalComponentArgsRest(__VLS_45));
    let __VLS_48;
    let __VLS_49;
    let __VLS_50;
    const __VLS_51 = {
        onConfirm: (__VLS_ctx.handleConfirm)
    };
    var __VLS_47;
}
/** @type {__VLS_StyleScopedClasses['upload-container']} */ ;
/** @type {__VLS_StyleScopedClasses['form-group']} */ ;
/** @type {__VLS_StyleScopedClasses['type-select-container']} */ ;
/** @type {__VLS_StyleScopedClasses['retry-btn']} */ ;
/** @type {__VLS_StyleScopedClasses['form-group']} */ ;
/** @type {__VLS_StyleScopedClasses['file-drop-zone']} */ ;
var __VLS_dollars;
const __VLS_self = (await Promise.resolve().then(() => __importStar(require('vue')))).defineComponent({
    setup() {
        return {
            $emit: emit,
            fileTypes: fileTypes,
            previewData: previewData,
            selectedTypeId: selectedTypeId,
            chunkType: chunkType,
            loadFileTypes: loadFileTypes,
            handleFileSelect: handleFileSelect,
            handleFileDrop: handleFileDrop,
            processFileUpload: processFileUpload,
            handleConfirm: handleConfirm,
        };
    },
});
exports.default = (await Promise.resolve().then(() => __importStar(require('vue')))).defineComponent({
    setup() {
        return Object.assign({ $emit: emit }, __VLS_exposed);
    },
});
; /* PartiallyEnd: #4569/main.vue */
